home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-05-05 | 25.7 KB | 939 lines | [TEXT/MPS ] |
- {Copyright © 1988 by Charles F. McMath All rights reserved.}
- CONST
- kPlotWindowID = 1001;
- kPlotDLOG = 2000;
- kPlotID = 'PPRM';
-
- kStaggerAmt = 16;
-
- cGraphColor = 1201; { these are command numbers }
- cAxisColor = 1202;
- cBackColor = 1203;
-
- cGrafBlack = 10001;
- cGrafWhite = 10002;
- cGrafRed = 10003;
- cGrafGreen = 10004;
- cGrafBlue = 10005;
- cGrafCyan = 10006;
- cGrafMagenta= 10007;
- cGrafYellow = 10008;
-
- cAxisBlack = 11001;
- cAxisWhite = 11002;
- cAxisRed = 11003;
- cAxisGreen = 11004;
- cAxisBlue = 11005;
- cAxisCyan = 11006;
- cAxisMagenta= 11007;
- cAxisYellow = 11008;
-
- cBackBlack = 12001;
- cBackWhite = 12002;
- cBackRed = 12003;
- cBackGreen = 12004;
- cBackBlue = 12005;
- cBackCyan = 12006;
- cBackMagenta= 12007;
- cBackYellow = 12008;
-
- cPrintWS = 1301;
- cPrintPS = 1302;
-
- (*
- * The following constants relate to DLOG and ALRT numbers.
- *)
- kAboutDLOG = 1024; { our about box DLOG ID }
- VAR
- gStaggerCount: INTEGER;
- colors: ARRAY [1..8] OF INTEGER;
- crString: Str255;
-
- {------------------------------------------------------------------------}
- FUNCTION Int2Str(theInt: INTEGER): Str255;
- (*
- * This utility function takes an integer and converts it into a
- * string.
- *)
- VAR
- tempLong: LongInt;
- tempStr: Str255;
- BEGIN
- tempLong := theInt;
- NumToString(tempLong, tempStr);
- Int2Str := tempStr;
- END; { Int2Str }
- {------------------------------------------------------------------------}
- FUNCTION Real2String(theReal: REAL; numDigits: INTEGER): Str255;
- (*
- * This function takes a real number, and converts it to a string with
- * the specified number of digits PAST the decimal point.
- *)
- VAR
- theForm: DecForm;
- xTemp: Extended;
- tempStr: DecStr;
- BEGIN
- theForm.style := FixedDecimal;
- theForm.digits := numDigits;
-
- xTemp := theReal;
- Num2Str(theForm, xTemp, tempStr);
- Real2String := tempStr;
- END; { Real2String }
- {------------------------------------------------------------------------}
- FUNCTION String2Real(theString: Str255): REAL;
- (*
- * This function takes a string form of a real number, and converts
- * it into the real number.
- *)
- VAR
- xTemp: Extended;
- BEGIN
- xTemp := Str2Num(theString);
- String2Real := Num2Real(xTemp);
- END; { String2Real }
- {------------------------------------------------------------------------}
- {------------------ QPlot Application Methods -------------------------}
- {------------------------------------------------------------------------}
- PROCEDURE TQPlotApplication.IQPlotApplication(itsMainFileType: OSType);
- (*
- * This procedure initializes the application. It sets up all of our
- * global variables and fills the color index array.
- *)
- VAR
- aQPlotView: TQPlotView;
- BEGIN
- IApplication(itsMainFileType);
-
- crString[0] := CHR(1);
- crString[1] := CHR(13);
-
- colors[1] := 33; { black }
- colors[2] := 30; { white }
- colors[3] := 205; { red }
- colors[4] := 341; { green }
- colors[5] := 409; { blue }
- colors[6] := 273; { cyan }
- colors[7] := 137; { magenta }
- colors[8] := 69; { yellow }
-
- fDefGraph := colors[3];
- fDefAxis := colors[1];
- fDefBack := colors[2];
- fPrintOpt := 1;
-
- gStaggerCount := 0;
- END; { TQPlotApplication.IQPlotApplication }
- {------------------------------------------------------------------------}
- FUNCTION TQPlotApplication.DoMakeDocument(itsCmdNumber: CmdNumber):
- TDocument; OVERRIDE;
- (*
- * This function is called whenever we're creating a new document. It
- * creates the document object and returns it (properly initialized, of
- * course).
- *)
- VAR
- aQPlotDocument: TQPlotDocument;
- BEGIN
- New(aQPlotDocument);
- FailNil(aQPlotDocument);
- aQPlotDocument.IQPlotDocument(kFileType, kSignature, kUsesDataFork,
- NOT kUsesRsrcFork, NOT kDataOpen, NOT kRsrcOpen);
-
- aQPlotDocument.fSavePrintInfo := FALSE;
- DoMakeDocument := aQPlotDocument;
- END; { TQPlotApplication.DoMakeDocument }
- {------------------------------------------------------------------------}
- PROCEDURE TQPlotApplication.HandleFinderRequest; OVERRIDE;
- BEGIN
- { just override this so we don't put up a blank document }
- END; { TQPlotApplication.HandleFinderRequest }
- {------------------------------------------------------------------------}
- PROCEDURE TQPlotApplication.DoSetupMenus; OVERRIDE;
- (*
- * This procedure enables the appropriate menu items for the application.
- *)
- BEGIN
- INHERITED DoSetupMenus;
-
- Enable(cGraphColor, TRUE);
- Enable(cAxisColor, TRUE);
- Enable(cBackColor, TRUE);
- (*
- * Enable all of these, and put a check by the current one.
- *)
- EnableCheck(cGrafBlack, TRUE, fDefGraph=colors[1]);
- EnableCheck(cGrafWhite, TRUE, fDefGraph=colors[2]);
- EnableCheck(cGrafRed, TRUE, fDefGraph=colors[3]);
- EnableCheck(cGrafGreen, TRUE, fDefGraph=colors[4]);
- EnableCheck(cGrafBlue, TRUE, fDefGraph=colors[5]);
- EnableCheck(cGrafCyan, TRUE, fDefGraph=colors[6]);
- EnableCheck(cGrafMagenta, TRUE, fDefGraph=colors[7]);
- EnableCheck(cGrafYellow, TRUE, fDefGraph=colors[8]);
-
- EnableCheck(cAxisBlack, TRUE, fDefAxis=colors[1]);
- EnableCheck(cAxisWhite, TRUE, fDefAxis=colors[2]);
- EnableCheck(cAxisRed, TRUE, fDefAxis=colors[3]);
- EnableCheck(cAxisGreen, TRUE, fDefAxis=colors[4]);
- EnableCheck(cAxisBlue, TRUE, fDefAxis=colors[5]);
- EnableCheck(cAxisCyan, TRUE, fDefAxis=colors[6]);
- EnableCheck(cAxisMagenta, TRUE, fDefAxis=colors[7]);
- EnableCheck(cAxisYellow, TRUE, fDefAxis=colors[8]);
-
- EnableCheck(cBackBlack, TRUE, fDefBack=colors[1]);
- EnableCheck(cBackWhite, TRUE, fDefBack=colors[2]);
- EnableCheck(cBackRed, TRUE, fDefBack=colors[3]);
- EnableCheck(cBackGreen, TRUE, fDefBack=colors[4]);
- EnableCheck(cBackBlue, TRUE, fDefBack=colors[5]);
- EnableCheck(cBackCyan, TRUE, fDefBack=colors[6]);
- EnableCheck(cBackMagenta, TRUE, fDefBack=colors[7]);
- EnableCheck(cBackYellow, TRUE, fDefBack=colors[8]);
-
- END; { TQPlotApplication.DoSetupMenus }
- {------------------------------------------------------------------------}
- FUNCTION TQPlotApplication.DoMenuCommand(aCmdNumber: CmdNumber): TCommand; OVERRIDE;
- (*
- * This function handles menu requests that pertain to the application. It
- * ensures that choices that change colors work correctly.
- *)
- BEGIN
- DoMenuCommand := gNoChanges;
- CASE aCmdNumber OF
- cAboutApp:
- ShowAboutApp;
- cGrafBlack,
- cGrafWhite,
- cGrafRed,
- cGrafGreen,
- cGrafBlue,
- cGrafCyan,
- cGrafMagenta,
- cGrafYellow:
- fDefGraph := colors[aCmdNumber - cGrafBlack + 1];
- cAxisBlack,
- cAxisWhite,
- cAxisRed,
- cAxisGreen,
- cAxisBlue,
- cAxisCyan,
- cAxisMagenta,
- cAxisYellow:
- fDefAxis := colors[aCmdNumber - cAxisBlack + 1];
- cBackBlack,
- cBackWhite,
- cBackRed,
- cBackGreen,
- cBackBlue,
- cBackCyan,
- cBackMagenta,
- cBackYellow:
- fDefBack := colors[aCmdNumber - cBackBlack + 1];
- cPrintWS,
- cPrintPS:
- fPrintOpt := aCmdNumber - cPrintWS + 1;
- OTHERWISE
- DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
- END; { case }
- END; { TQPlotApplication.DoMenuCommand }
- {------------------------------------------------------------------------}
- PROCEDURE DrawBox(wPtr: WindowPtr; itemNum: INTEGER);
- (*
- * This procedure is the UserItem proc that gets called for the about box.
- *)
- VAR
- ityp: INTEGER;
- itemHdl: Handle;
- tRect: Rect;
- BEGIN
- GetDItem(DialogPtr(wPtr), 5, ityp, itemHdl, tRect);
- FrameRect(tRect);
- END; { DrawBox }
- {------------------------------------------------------------------------}
- PROCEDURE TQPlotApplication.ShowAboutApp;
- (*
- * Show our about box. This version is almost identical to the original,
- * except for the addition of some stuff about MacApp (incidentally, this
- * is required by the license agreement for programs developed with MacApp!)
- *)
- VAR
- idStrHandle: StringHandle;
- freeSpace: Size;
- myHeapSpace: LongInt;
- tempStr1: Str255;
- tempStr2: Str255;
- tempStr3: Str255;
- diaPtr: DialogPtr;
- itemHit: INTEGER;
-
- ityp: INTEGER;
- itemHdl: Handle;
- tRect: Rect;
- BEGIN
- idStrHandle := StringHandle(GetResource(kSignature, 0));
- FailNIL(idStrHandle);
-
- MoveHHi(Handle(idStrHandle));
- HLock(Handle(idStrHandle));
-
- freeSpace := FreeMem;
- myHeapSpace := MaxMem(freeSpace);
- NumToString(myHeapSpace, tempStr2);
- tempStr2 := concat('Memory = ', tempStr2);
- tempStr3 := '';
- tempStr1 := '';
- ParamText(idStrHandle^^, tempStr1, tempStr2, tempStr3);
- diaPtr := GetNewDialog(kAboutDLOG, NIL, Pointer(-1));
- FailNIL(diaPtr);
- GetDItem(diaPtr, 5, ityp, itemHdl, tRect);
- SetDItem(diaPtr, 5, ityp, Handle(@DrawBox), tRect);
-
- InitCursor;
- ModalDialog(NIL, itemHit);
- DisposDialog(diaPtr);
-
- HUnlock(Handle(idStrHandle));
- END; { TQPlotApplication.ShowAboutApp }
- {------------------------------------------------------------------------}
- {------------------- QPlot Document Methods ---------------------------}
- {------------------------------------------------------------------------}
- PROCEDURE TQPlotDocument.IQPlotDocument(itsFileType, itsCreator: OSType;
- usesDataFork, usesRsrcFork: BOOLEAN;
- keepsDataOpen, keepsRsrcOpen: BOOLEAN);
- (*
- * Initialize the QPlot document. For our document, this means that we
- * will present the dialog box that asks for the quadratic parameters,
- * and we'll solve the equation while we're here.
- *)
- VAR
- x1, x2: REAL;
- BEGIN
- IDocument(itsFileType, itsCreator, usesDataFork, usesRsrcFork,
- keepsDataOpen, keepsRsrcOpen);
-
- PosePlotDialog;
- fResult := SolveIt(fAParam, fBParam, fCParam, x1, x2);
- IF (fResult<>-1) THEN
- BEGIN
- fRoot1 := x1;
- fRoot2 := x2;
- END
- ELSE
- BEGIN
- fRoot1 := -999;
- fRoot2 := -999
- END;
- fPlotView := NIL;
- END; { TQPlotDocument.IQPlotDocument }
- {------------------------------------------------------------------------}
- PROCEDURE TQPlotDocument.DoMakeWindows; OVERRIDE;
- (*
- * This procedure is called when we have to make a new document (and its
- * associated window). We just get a simple window and shove it on the
- * screen.
- *)
- VAR
- aWindow: TWindow;
- BEGIN
- aWindow := NewSimpleWindow(kPlotWindowID,
- kWantHScrollBar, kWantVScrollBar,
- SELF, fPlotView);
- aWindow.SimpleStagger(kStaggerAmt, kStaggerAmt, gStaggerCount);
- END; { TQPlotDocument.DoMakeWindows }
- {------------------------------------------------------------------------}
- PROCEDURE TQPlotDocument.DoMakeViews(forPrinting: BOOLEAN); OVERRIDE;
- (*
- * This procedure is called when we are making a new document. It creates
- * all views that are needed. In our case, it's only one. We then initialize
- * the view.
- *)
- VAR
- plotApp: TQPlotApplication;
- aQPlotView: TQPlotView;
- aHandler: TStdPrintHandler;
- tRect: Rect;
- BEGIN
- plotApp := TQPlotApplication(gApplication);
-
- NEW(aQPlotView);
- FailNIL(aQPlotView);
- aQPlotView.IQPlotView(SELF, plotApp.fDefGraph, plotApp.fDefAxis,
- plotApp.fDefBack);
-
- fPlotView := aQPlotView;
- (*
- * Now make the view printable by creating a print handler.
- *)
- IF NOT(forPrinting) THEN
- BEGIN
- New(aHandler);
- FailNIL(aHandler);
- aHandler.IStdPrintHandler(SELF, aQPlotView, FALSE, TRUE, TRUE);
- SetRect(tRect,35,35,-35,-35); { set up for 1/2" margins }
- aHandler.InstallMargins(tRect, FALSE);
- END;
- END; { TQPlotDocument.DoMakeViews }
- {------------------------------------------------------------------------}
- PROCEDURE TQPlotDocument.PosePlotDialog;
- (*
- * This procedure puts up the dialog that requests the quadratic parameters.
- *)
-
- FUNCTION CvtEditReal(aText: TEditText): Real;
- VAR
- tempStr: Str255;
- BEGIN
- aText.GetText(tempStr);
- CvtEditReal := String2Real(tempStr);
- END; { CvtEditReal }
-
- FUNCTION CvtEditInt(aText: TEditText): INTEGER;
- VAR
- tempStr: Str255;
- tempLong: LongInt;
- BEGIN
- aText.GetText(tempStr);
- StringToNum(tempStr, tempLong);
- CvtEditInt := tempLong;
- END; { CvtEditInt }
- VAR
- aWindow: TWindow;
- dismisser: IDType;
-
- aQPlotView: TQPlotView;
- dView: TDialogView;
- anEditText: TEditText;
- aVal: TEditText;
- bVal: TEditText;
- cVal: TEditText;
- stepVal: TEditText;
- xVal: TEditText;
- yVal: TEditText;
-
- tempStr: Str255;
- BEGIN
- (*
- * First make our calls (which never get executed)
- * to tell the linker we want to create these types of objects.
- *)
- IF gCreateWithTemplates THEN
- BEGIN
- NEW(aQPlotView);
- NEW(dView);
- NEW(anEditText);
- END;
- (*
- * Get the dialog window and find the dialog subview.
- *)
- aWindow := NewTemplateWindow(kPlotDLOG, NIL);
- dView := TDialogView(aWindow.FindSubView(kPlotID));
- (*
- * Retrieve references to each of the edit text items. We
- * will need to reference them later to get their values.
- *)
- aVal := TEditText(dView.FindSubView('a '));
- bVal := TEditText(dView.FindSubView('b '));
- cVal := TEditText(dView.FindSubView('c '));
- stepVal := TEditText(dView.FindSubView('step'));
- xVal := TEditText(dView.FindSubView('xscl'));
- yVal := TEditText(dView.FindSubView('yscl'));
-
- dView.SelectEditText('a ', kRedraw);
-
- dismisser := dView.PoseModally;
- (*
- * Now that we have the values, convert them to numbers and plug them into
- * the quadratic equation solver. Note that we don't test to see if
- * the OK button was pressed, because in this dialog, you can't exit
- * except by saying OK.
- *)
- fAParam := CvtEditReal(aVal);
- fBParam := CvtEditReal(bVal);
- fCParam := CvtEditReal(cVal);
- fStep := CvtEditReal(stepVal);
- fXScale := CvtEditInt(xVal);
- fYScale := CvtEditInt(yVal);
-
- aWindow.Close;
- END; { TQPlotDocument.PosePlotDialog }
- {------------------------------------------------------------------------}
- PROCEDURE TQPlotDocument.Quad(a, b, c : REAL;VAR x1, x2 : REAL;
- VAR result : INTEGER);
- (*
- * This procedure is identical to the one written in 'vanilla' Pascal
- *)
- VAR
- check : real;
-
- FUNCTION PositiveCalc (a, b, check : real) : real;
- BEGIN
- PositiveCalc := (-b + sqrt(check)) / (2 * a);
- END; { PositiveCalc ---------------------- }
-
- FUNCTION NegativeCalc (a, b, check : real) : real;
- BEGIN
- NegativeCalc := (-b - sqrt(check)) / (2 * a);
- END; { NegativeCalc ---------------------- }
-
- BEGIN
- result := 0;
- check := (b * b) - (4 * a * c);
- IF result = 0 THEN
- BEGIN
- { Check if double root exists }
- IF check = 0 THEN
- BEGIN
- result := 2;
- x1 := positivecalc(a, b, check);
- x2 := x1;
- END;
- { Check if real result}
- IF check > 0 THEN
- BEGIN
- result := 1;
- x1 := positivecalc(a, b, check);
- x2 := negativecalc(a, b, check);
- END;
- { Check if root is complex }
- IF check < 0 THEN
- BEGIN
- result := 3;
- check := -check;
- x1 := positivecalc(a, b, check);
- x2 := negativecalc(a, b, check);
- END;
- END;
- END; { TQPlotDocument.Quad }
- {------------------------------------------------------------------------}
- FUNCTION TQPlotDocument.SolveIt(a, b, c: REAL; VAR x1, x2: REAL): INTEGER;
- (*
- * This function is identical to the one written for the original program.
- *)
- VAR
- result: INTEGER;
- BEGIN
- IF (a <> 0) THEN
- quad(a, b, c, x1, x2, result)
- ELSE
- result := -1;
- SolveIt := result;
- END; { TQPlotDocument.SolveIt }
- {------------------------------------------------------------------------}
- PROCEDURE TQPlotDocument.DoNeedDiskSpace(VAR dataForkBytes,
- rsrcForkBytes: LONGINT); OVERRIDE;
- (*
- * This procedure calculates the amount of disk space we need to store
- * our document on disk. In our case, it's just the size of the drawing
- * since no additional information is stored in our file.
- *)
- BEGIN
- INHERITED DoNeedDiskSpace(dataForkBytes, rsrcForkBytes);
-
- dataForkBytes := dataForkBytes + 512 { header } +
- GetHandleSize(Handle(fPlotView.fDrawing));
- END; { TQPlotDocument.DoNeedDiskSpace }
- {------------------------------------------------------------------------}
- PROCEDURE TQPlotDocument.DoWrite(aRefNum: INTEGER; makingCopy: BOOLEAN); OVERRIDE;
- (*
- * This procedure is called to write the data onto the disk.
- *)
- VAR
- count: LongInt;
- buffer: ARRAY [1..256] OF INTEGER;
- pHdl: PicHandle;
- i: INTEGER;
- err: OSErr;
- BEGIN
- INHERITED DoWrite(aRefNum, makingCopy); { create file, etc }
- (*
- * Now write the blank 512 byte header needed for PICT files.
- *)
- FOR i:= 1 TO 256 DO
- buffer[i] := 0;
-
- count := 512;
- err := FSWrite(aRefNum, count, @buffer);
- IF ((err<>noErr) OR (count<>512)) THEN
- SysBeep(10); { @@@ error alert }
-
- pHdl := fPlotView.fDrawing;
- HLock(Handle(pHdl));
- count := GetHandleSize(Handle(pHdl));
- err := FSWrite(aRefNum, count, Ptr(pHdl^));
- HUnlock(Handle(pHdl));
- IF ((err<>noErr) OR (count <> GetHandleSize(Handle(pHdl)))) THEN
- SysBeep(10); { @@@ error alert }
- END; { TQPlotDocument.DoWrite }
- {------------------------------------------------------------------------}
- {--------------------- QPlot View Methods -----------------------------}
- {------------------------------------------------------------------------}
- PROCEDURE TQPlotView.IQPlotView(theDoc: TQPlotDocument; theGrafColor,
- theAxisColor, theBackColor: INTEGER);
- (*
- * This procedure is called to initialize a QPlot view. It sets the
- * view's variables to good initial values.
- *)
- VAR
- vOrigin: VPoint;
- vSize: VPoint;
- tempPort: GrafPtr;
- BEGIN
- SetVPt(vOrigin, 0, 0);
- SetVPt(vSize, 600, 400);
-
- IView(theDoc, NIL, vOrigin, vSize, sizeVariable, sizeVariable);
- fPlotDoc := theDoc;
-
- fDrawing := NIL;
- fOnePage := FALSE;
- END; { TQPlotView.IQPlotView }
- {------------------------------------------------------------------------}
- PROCEDURE TQPlotView.Free; OVERRIDE;
- (*
- * This procedure is called when the view is finished, and we are cleaning
- * up any space we have allocated. We just dispose of the picture handle.
- *)
- BEGIN
- KillPicture(fDrawing);
- INHERITED Free;
- END; { TQPlotView.Free }
- {------------------------------------------------------------------------}
- PROCEDURE TQPlotView.CalcMinSize(VAR minSize: VPoint); OVERRIDE;
- (*
- * This procedure is called to calculate the minimum size of the view.
- * It is called initially when the view is being created, and later on
- * when we tell the view to recalculate its view size.
- *)
- VAR
- vSize: Point;
- tWind: TWindow;
- tRect: Rect;
- BEGIN
- INHERITED CalcMinSize(minSize);
- IF fOnePage THEN
- BEGIN
- minSize := fPrintHandler.fViewPerPage;
- END
- ELSE
- BEGIN
- IF (fSuperView<>NIL) THEN
- minSize := fSuperView.fSize
- ELSE
- BEGIN
- vSize := Point(0);
- IF SELF.Focus THEN
- Writeln('focus worked!');
- QDToViewPt(vSize, minSize);
- END;
- END;
- END; { TQPlotView.CalcMinSize }
- {------------------------------------------------------------------------}
- PROCEDURE TQPlotView.DoSetupMenus; OVERRIDE;
- (*
- * This procedure is called to enable menu items that pertain to
- * the view.
- *)
- BEGIN
- INHERITED DoSetupMenus;
-
- EnableCheck(cPrintWS, TRUE, NOT fOnePage);
- EnableCheck(cPrintPS, TRUE, fOnePage);
- END; { TQPlotView.DoSetupMenus }
- {------------------------------------------------------------------------}
- FUNCTION TQPlotView.DoMenuCommand(aCmdNumber: CmdNumber): TCommand; OVERRIDE;
- (*
- * This function is called to handle menu commands that pertain to
- * the view.
- *)
- VAR
- tempVPt: VPoint;
- tRect: Rect;
- BEGIN
- DoMenuCommand := gNoChanges;
- IF (aCmdNumber = cPrintWS) OR (aCmdNumber = cPrintPS) THEN
- BEGIN
- fOnePage := (aCmdNumber=cPrintPS);
- AdjustSize;
- END
- ELSE
- DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
- END; { TQPlotView.DoMenuCommand }
- {------------------------------------------------------------------------}
- PROCEDURE TQPlotView.PrQDStuff(pRect : rect; QDdevice : integer);
- (*
- * This is the main drawing procedure for the view. It is (almost) unchanged
- * from the original version. Since in MacApp you don't know who you're
- * drawing for (Display vs. LaserWriter) most of the display-specific code has
- * been deleted. Drawing still works correctly, since we erase the invalid
- * areas before we draw it.
- *)
- CONST
- Display = 1;
- LaserWriter = 2;
- ImageWriter = 3;
-
- NoJust = 0;
- LeftJust = 1;
- CenterJust = 2;
- RightJust = 3;
- FullJust = 4;
- LinesInParagraph = 5;
- {selected MacDraw comments}
- picDwgBeg = 130;
- picDwgEnd = 131;
- picGrpBeg = 140;
- picGrpEnd = 141;
- TextBegin = 150;
- TextEnd = 151;
- StringBegin = 151;
- StringEnd = 153;
- TextCenter = 154;
- {postscript comments}
- SetLineWidth = 182;
- PostScriptBegin = 190;
- TextIsPostscript = 194;
- PostScriptEnd = 191;
- TYPE
- widhdl = ^widptr;
- widptr = ^widpt;
- widpt = Point;
-
- TTxtPicRec = PACKED RECORD
- tJus : Byte;
- tFlip : Byte;
- tRot : Integer;
- tLine : Byte;
- tCmnt : Byte;
- END;
-
- VAR
- le, tp, ri, bo : integer;
- str1, str2, str3, str4, str5 : str255;
- str6, str7, str8, str9 : str255;
- hPos, vPos, hor, ver : integer;
- x, y, z1, z2 : real;
- rBox, ClipBox : rect;
- Width : Widhdl;
- leading : integer;
- LineNo : integer;
- ParagraphBegin : Point;
- Indent : integer;
- Paragraph : ARRAY[1..LinesInParagraph] OF str255;
- TxtPicRec : TTxtPicRec;
- TxtPicPtr : QDPtr;
- TxtPicHdl : QDHandle;
- TextClipRgn : RgnHandle;
- SaveClip : RgnHandle;
- fInfo : FontInfo;
-
- BEGIN
- SaveClip := NewRgn;
- GetClip(SaveClip);
- ClipRect(pRect);
- TextClipRgn := NewRgn;
-
- penNormal;
-
- TextFont(geneva);
- TextSize(10);
- TextFace([]);
-
- hor := (pRect.right - pRect.left) DIV 2;
- ver := (pRect.bottom - pRect.top) DIV 2;
- Width := Widhdl(NewHandle(sizeof(widpt)));
- Width^^.h := 10;
- Width^^.v := 1;
- TxtPicPtr := @TxtPicRec;
- TxtPicHdl := @TxtPicPtr;
- TxtPicRec.tJus := LeftJust;
- TxtPicRec.tFlip := 0; {no flip}
- TxtPicRec.tRot := 0; {no rotation}
- TxtPicRec.tLine := 2; {1 1/2 spacing}
- GetFontInfo(fInfo);
- leading := fInfo.descent + fInfo.ascent + fInfo.leading;
- Indent := 2;
- WITH fPlotDoc DO
- BEGIN
- x := -fXScale / 2;
- y := fAParam * x * x + (fBParam * x) + fCParam;
- hPos := INTEGER(ROUND(x * hor * 2 / fXScale + hor));
- vPos := INTEGER(round(-y * ver * 2 / fYScale + ver));
- z1 := -fBParam / (2 * fAParam);
- z2 := (4 * fAParam * fCParam - (fBParam * fBParam)) / (4 * fAParam);
- END;
- le := 2;
- tp := ver + (ver DIV 3);
- ri := 140;
- IF ri >= (hor + hor DIV 3) THEN
- ri := hor + hor DIV 3;
- bo := ver + ver - 2;
- setRect(rBox, le, tp - 14, ri, bo);
- ParagraphBegin.h := 4;
- ParagraphBegin.v := tp;
-
- {Graph Text}
- WITH fPlotDoc DO
- BEGIN
- str1 := Int2Str(-fXScale DIV 2);
- str2 := Int2Str(fYScale DIV 2);
- str3 := Int2Str(fXScale DIV 2);
- str4 := Int2Str(-fYScale DIV 2);
-
- Paragraph[1] := CONCAT('y=ax^2 + bx + c', crString);
- Paragraph[2] := CONCAT('a=', Real2String(fAParam,1), ', b=', Real2String(fBParam,1), ', c=', Real2String(fCParam,1), crString);
- Paragraph[3] := CONCAT('x1=', Real2String(fRoot1,2), ', x2=', Real2String(fRoot2,2), crString);
- END;
-
- CASE fPlotDoc.fResult OF
- 1 :
- Paragraph[4] := CONCAT('Two Real Roots, x1, x2', crString);
- 2 :
- Paragraph[4] := CONCAT('Double Root', crString);
- 3 :
- Paragraph[4] := CONCAT('Two Complex Roots ', crString);
- OTHERWISE
- ;
- END;
- Paragraph[5] := CONCAT('Slope 0 = (', Real2String(z1, 1), ',',Real2String(z2,1), ')', crString);
-
- PenNormal;
- BackColor(TQPlotApplication(gApplication).fDefBack);
- ForeColor(TQPlotApplication(gApplication).fDefAxis);
-
- {Drawing Boundry}
- PicComment(picDwgBeg, 0, NIL); {Begin MacDraw Document}
- PicComment(picGrpBeg, 0, NIL);
- PicComment(SetLineWidth, GetHandleSize(Handle(Width)), Handle(Width));
-
- IF QDdevice = Display THEN
- FillRect(pRect, white);
- FrameRect(pRect);
-
-
- {Two Axis}
- PicComment(picGrpBeg, 0, NIL);
- moveto(0, ver);
- line(hor + hor, 0);
- moveto(hor, 0);
- line(0, ver + ver);
- PicComment(picGrpEnd, 0, NIL);
-
- ForeColor(TQPlotApplication(gApplication).fDefGraph);
-
- {Plot Itsef}
- PicComment(picGrpBeg, 0, NIL);
- moveto(hPos, vPos);
- WITH fPlotDoc DO
- REPEAT
- x := x + fStep;
- y := fAParam * x * x + (fBParam * x) + fCParam;
- hPos := integer(round(x * hor * 2 / fXScale + hor));
- vPos := integer(round(-y * ver * 2 / fYScale + ver));
- WITH pRect DO
- IF (hPos < right) AND (hPos > left) AND (vPos < bottom) AND (vPos > top) THEN
- LineTo(hPos, vPos)
- ELSE
- moveto(hPos, vPos);
- UNTIL x >= fXScale / 2;
- PicComment(picGrpEnd, 0, NIL);
-
- ForeColor(Colors[1]);
-
- {Axis Text}
- moveto(4, ver + 14);
- DrawString(str1);
- moveto(hor - 40, 14);
- DrawString(str2);
- moveto(hor + hor - 50, ver + 14);
- DrawString(str3);
- moveto(hor - 40, ver + ver - 14);
- DrawString(str4);
-
- {Box }
- PicComment(picGrpBeg, 0, NIL);
- PicComment(picGrpBeg, 0, NIL);
-
- PicComment(SetLineWidth, GetHandleSize(Handle(Width)), Handle(Width));
-
- IF QDdevice = Display THEN
- fillRect(rBox, white);
- frameRect(rBox);
- PicComment(picGrpEnd, 0, NIL); {of box}
-
- GetClip(TextClipRgn);
- ClipBox := rBox;
- ClipRect(ClipBox);
-
- {Box Text}
- PicComment(TextBegin, sizeof(TTxtPicRec), Handle(TxtPicHdl));
- FOR LineNo := 1 TO LinesInParagraph DO
- BEGIN
- moveto(ParagraphBegin.h, ParagraphBegin.v);
- move(Indent, (LineNo - 1) * leading);
- DrawString(Paragraph[LineNo]);
- END;
- PicComment(TextEnd, 0, NIL);
- PicComment(PicGrpEnd, 0, NIL); {of Box & text}
- PicComment(PicGrpEnd, 0, NIL); {of select all objects}
- picComment(picDwgEnd, 0, NIL); {of drawing}
-
- SetClip(SaveClip);
- disposHandle(handle(width));
- DisposeRgn(TextClipRgn);
- DisposeRgn(SaveClip);
- END; { TQPlotView.PrQDStuff }
- {------------------------------------------------------------------------}
- PROCEDURE TQPlotView.SuperViewChangedSize (delta: VPoint;
- invalidate: BOOLEAN); OVERRIDE;
- (*
- * This procedure changes the view size when the window is resized.
- *)
- BEGIN
- (*
- * We only need to go through these shenanigans if we are NOT
- * displaying a page-sized picture. This resizes the view's extent
- * rectangle and invalidates the area, forcing the view to redraw
- * the picture in the new size.
- *)
- IF NOT(fOnePage) THEN
- BEGIN
- AdjustSize;
- ForceRedraw;
- END;
- END; { TQPlotView.SuperViewChangedSize }
- {------------------------------------------------------------------------}
- PROCEDURE TQPlotView.Resize (width, height: VCoordinate;
- invalidate: BOOLEAN); OVERRIDE;
- (*
- * This procedure is called from AdjustSize. It is here because when
- * we toggle between Page Size and Window Size plots, we need to
- * tell the view to redraw itself (because it changed size, even though
- * the window didn't).
- *)
- BEGIN
- ForceRedraw;
- INHERITED Resize(width, height, FALSE);
- ForceRedraw;
- END; { TQPlotView.Resize }
- {------------------------------------------------------------------------}
- PROCEDURE TQPlotView.Draw(area: Rect); OVERRIDE;
- (*
- * This procedure is called to draw the view when it needs to be drawn.
- * The picture we created before is ALWAYS drawn to take up the entire window.
- *)
- VAR
- tRect: Rect;
- BEGIN
-
- GetQDExtent(tRect); { always draw pict to fill entire extent of the view }
- EraseRect(tRect);
- IF (fDrawing=NIL) THEN
- BEGIN
- fDrawing := OpenPicture(tRect);
- PrQDStuff(tRect, 1);
- ClosePicture;
- PenNormal;
- END;
- DrawPicture(fDrawing, tRect);
- END; { TQPlotView.Draw }
-